﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace welwitschia.Administracao
{
    public partial class UtilizadoresLista : PaginaBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindListView();
        }

        protected void Unnamed1_Click(object sender, EventArgs e)
        {
            Response.Redirect(@"~\Administracao\UtilizadorDetalhe.aspx");
        }

        protected void lvUtilizadores_ItemDeleting(object sender, ListViewDeleteEventArgs e)
        {
            try
            {
                Membership.DeleteUser(e.Keys["UserName"].ToString());
                BindListView();
            }
            catch (Exception ex)
            {
                MostraErro(ex.Message);
            }
        }

        protected void lvUtilizadores_ItemEditing(object sender, ListViewEditEventArgs e)
        {
        }

        protected void lvUtilizadores_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
                Response.Redirect(@"~\Administracao\UtilizadorDetalhe.aspx?un=" + e.CommandArgument.ToString());  

        }

        #region Metodos auxiliares

        private void BindListView()
        {
            MembershipUserCollection users = Membership.GetAllUsers();
            lvUtilizadores.DataSource = users;
            lvUtilizadores.DataBind();
        }

        #endregion
    }
}